<?php

class move extends adminControl
{
	protected function indexAction()
	{
		require_once(R_P . 'data/cache/server.php');
		$serverdb = array();
		$serverSelect = '<select name="toId"><option value=0>请选择</option>';
		foreach ($server as $serverId => $serverInfo)
		{
			$serverSelect .= "<option value='$serverId'> $serverInfo[servername] </option>";
			$serverdb[$serverId] = $serverInfo;
			$r = $this->db->get_one("SELECT SUM(size) AS total FROM cms_resource WHERE serverid='$serverId'");
			$serverdb[$serverId]['use'] = round($r['total']/1000000, 2);
		}
		$serverSelect .= '</select>';

		$this->fillData('serverSelect', $serverSelect);
		$this->fillData('serverdb', $serverdb);
		$this->display('set_move');
	}

	protected function getMoveAction()
	{
		Showmsg('对不起，此功能暂时不开放。');
		$fromId = intval($_GET['fromId']);
		$toId	= intval($_GET['toId']);
		if (empty($fromId) || empty($toId))
		{
			start();
			exit('错误');
		}
		if ($fromId == $toId)
		{
			start();
			exit('源存储点和目标存储点相同');
		}
		$rs = $this->db->query("SELECT * FROM cms_resource WHERE serverid='$fromId' LIMIT 10");
		require_once(R_P . 'data/cache/server.php');
		require_once(R_P . 'require/class_file.php');
		$fromPath = $server[$fromId]['serverpath'];
		$toPath = $server[$toId]['serverpath'];
		$moveIds = array();
		while ($f = $this->db->fetch_array($rs))
		{
			File::checkDir($toPath . $f['filepath']);
			echo $fromPath . $f['filepath'] . "<BR>";
				echo $toPath . $f['filepath'] . "<BR><BR>";
			if (copy($fromPath . $f['filepath'], $toPath . $f['filepath']))
			{
				
				$moveIds[] = $f['rid'];
				unlink($fromPath . $f['filepath']); //删除原来文件
			}
		}
		if (!empty($moveIds))
		{
			$moveIds = implode(',', $moveIds);
			$this->db->query("UPDATE cms_resource SET serverid='$toId' WHERE rid IN($moveIds)");
		}
		exit('D');

	}
}

new move();
?>